<?php

use console\db\Migration;

/**
 * 创建排查相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m190102_100002_t_survey extends Migration {

    /**
     * 检测记录表
     * @table `survey`
     */
    public function buildTableSurvey() {
        return [
            'comment' => '核酸检测记录表',
            'columns' => [
                'id' => $this->primaryKey(),
                'round_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('检测轮次ID'),
                'resident_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('居民身份ID'),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                //
                'result' => $this->char(255)->comment('扫码结果'),
                'char_set' => $this->char(255)->comment('字符集'),
                'scan_type' => $this->char(255)->comment('扫码类型'),
                'raw_data' => $this->char(255)->comment('加密串'),
                //
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ],
            'index' => [
                [
                    'columns' => 'round_id',
                ],
                [
                    'columns' => 'resident_id',
                ],
                [
                    'columns' => ['deleted_at', 'status'],
                ],
                [
                    'columns' => 'deleted_at',
                ],
                [
                    'columns' => 'status',
                ],
            ]
        ];
    }

    /**
     * 筛查轮次
     * @table `survey_round`
     */
    public function buildTableSurveyRound() {
        return [
            'comment' => '筛查轮次',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(255)->notNull()->comment('轮次名称'),
                'description' => $this->string(255)->comment('描述/备注'),
                'begin_time' => $this->unixTimestamp()->comment('开始时间'),
                'end_time' => $this->unixTimestamp()->comment('结束时间'),
                'mark' => $this->text()->comment('说明'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ],
            'index' => [
                [
                    'columns' => 'begin_time',
                ],
                [
                    'columns' => 'end_time',
                ],
                [
                    'columns' => ['deleted_at', 'status'],
                ],
                [
                    'columns' => 'deleted_at',
                ],
                [
                    'columns' => 'status',
                ],
            ]
        ];
    }

}
